<%--
  Created by IntelliJ IDEA.
  User: 86157
  Date: 2022/1/11
  Time: 19:47
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>制定工序物料设计单</title>
</head>
<body>
<div id="module">
    <table id="wlmodule">

    </table>
</div>

<div id="module2" style="display: none">
    <div style="position: absolute; right: 10%">
        <input type="button" value="提交" class="btn btn-primary" id="tjmodule">
        <input type="button" value="返回" class="btn btn-primary" id="reswl">
    </div><br><br>
    <form id="module_add_form" class="form form-horizontal">
        <h4 align="center">工序物料设计单</h4><br>
        <div class="row">

            <div class="form-group col-md-6">
                <label class="control-label col-md-4">设计单编号 </label>
                <div class="col-md-8">
                    <input type="text" class="form-control" name="designId" id="mod_designId" readonly="readonly">
                </div>
            </div>

            <div class="form-group col-md-6">
                <label class="control-label col-md-4">设计人 </label>
                <div class="col-md-8">
                    <input type="text" class="form-control" name="designer" id="mod_designer" readonly="readonly">
                </div>
            </div>
        </div>

        <div class="row">
            <div class="form-group col-md-6">
                <label class="control-label col-md-4">产品名称 </label>
                <div class="col-md-8">

                    <input type="text" class="form-control" name="productName" id="mod_productName" readonly="readonly">
                    </select>
                </div>
            </div>
            <div class="form-group col-md-6">
                <label class="control-label col-md-4">产品编号 </label>
                <div class="col-md-8">
                    <input type="text" class="form-control" name="productId" id="mod_productId" readonly="readonly">

                </div>
            </div>
        </div>

        <div class="row" align="center">
            <table id="sjmodule" style="width: 900px;height: 60px;" >

            </table>
        </div>
        <br>
        <div class="row">
            <div class="form-group col-md-6">
                <label class="control-label col-md-4">工时总成本 </label>
                <div class="col-md-8">
                    <input type="text" class="form-control" name="costPriceSum" id="mod_costPriceSum" readonly="readonly">
                    </select>
                </div>
            </div>
            <div class="form-group col-md-6">
                <label class="control-label col-md-4">物料总成本 </label>
                <div class="col-md-8">
                    <input type="text" class="form-control" id="wlPriceSum" readonly="readonly">

                </div>
            </div>

        </div>
        <div class="row">
            <div class="form-group col-md-12">
                <label class="control-label col-md-2">设计要求 </label>
                <div class="col-md-10">
                    <input type="text" class="form-control" name="procedureDescribe" id="mod_procedureDescribe" readonly="readonly">
                    </select>
                </div>
            </div>
        </div>

        <div class="row">
            <div class="form-group col-md-6">
                <label class="control-label col-md-4">审核人 </label>
                <div class="col-md-8">

                    <input type="text" class="form-control" name="checker" id="mod_checker" readonly="readonly">
                    </select>
                </div>
            </div>
            <div class="form-group col-md-6">
                <label class="control-label col-md-4">审核时间 </label>
                <div class="col-md-8">
                    <input type="text" class="form-control" id="modtime" readonly="readonly">

                </div>
            </div>
        </div>
    </form>

    <!-- 模态框  选择物料  指向 childdemo页面-->
    <div id="openmodule" class="modal">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-body">
                </div>
            </div>
        </div>
    </div>
</div>


<script>

    var params= {
        url: "${pageContext.request.contextPath}/queryalldesign.action",
        method: 'GET',                      //请求方式（*）
        //toolbar: '#toolbar',              //工具按钮用哪个容器
        striped: true,                      //是否显示行间隔色
        cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
        pagination: true,                   //是否显示分页（*）
        sortable: true,                     //是否启用排序
        sortOrder: "asc",                   //排序方式
        sidePagination: "server",           //分页方式：client客户端分页，server服务端分页（*）
        pageNumber: 1,                      //初始化加载第一页，默认第一页,并记录
        pageSize: 5,                     //每页的记录行数（*）
        pageList: [5, 10, 25, 50, 100],        //可供选择的每页的行数（*）
        search: false,                      //是否显示表格搜索
        strictSearch: true,
        showColumns: true,                  //是否显示所有的列（选择显示的列）
        showRefresh: true,                  //是否显示刷新按钮
        minimumCountColumns: 2,             //最少允许的列数
        clickToSelect: true,                //是否启用点击选中行
        height: 500,                      //行高，如果没有设置height属性，表格自动根据记录条数觉得表格高度
        uniqueId: "productId",            //每一行的唯一标识，一般为主键列
        showToggle: true,                   //是否显示详细视图和列表视图的切换按钮
        cardView: false,                    //是否显示详细视图
        detailView: false,                  //是否显示父子表
        //传递额外的查询用的参数
        queryParams: function (params) {
            //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
            var temp = {
                pagesize: params.limit,                         //页面大小
                pageno: (params.offset / params.limit) + 1,   //页码
                //checkTag: "S001-1", //查询条件  已审核 （通过and不通过）

            };
            return temp;
        },
        columns: [
            {
                title: "设计单编号",
                    field: "designId"
            },
            {
                title: "产品编号",
                field: "productId"
            },
            {
                title: "产品名称",
                field: "productName"
            },
            {
                title: "设计人",
                field: "designer"
            },
            {
                title: "登记时间",
                field: "registerTime"
            },
            {
                title: "工时总成本",
                field: "costPriceSum"
            },
            {
                title: "制定",
                field: "",
                formatter: function (value, row, index) {
                    return "<input type='button' onclick='ckmodule(" + row.designId + ")' value='制定' class='btn btn-primary'>" ;
                }
            }

        ]
    };
    $("#wlmodule").bootstrapTable(params);


    //制定
   function ckmodule(designId) {
        $.get("${pageContext.request.contextPath}/querydesignbydid.action",{id:designId},function (data) {
            $("#mod_designId").val(data.designId);
            $("#mod_productName").val(data.productName);
            $("#mod_productId").val(data.productId);
            $("#mod_designer").val(data.designer);
            $("#mod_costPriceSum").val(data.costPriceSum);
            $("#mod_checker").val(data.checker);
            //页面显示变更时间
            var dDate = new Date();
            var sDate = dDate.getFullYear() + "/" + (dDate.getMonth() + 1) + "/" + dDate.getDate();
            sDate = sDate + " " + dDate.getHours() + ":" + dDate.getMinutes() + ":" + dDate.getSeconds();
            $("#modtime").val(sDate);

            //表格数据加载
            var paramsmodule= {
                url:"${pageContext.request.contextPath}/querydesignDetailsbydid.action",
                striped: true,                      //是否显示行间隔色
                showRefresh: true,                  //是否显示刷新按钮
                clickToSelect: true,                //是否启用点击选中行
                height: 300,                      //行高，如果没有设置height属性，表格自动根据记录条数觉得表格高度
                uniqueId: "procedureId",                     //每一行的唯一标识，一般为主键列
                //传递额外的查询用的参数
                queryParams: function (params) {
                    //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                    var temp = {
                        id: data.id  //查询条件
                    };
                    return temp;
                },
                columns: [
                    {
                        title: "序号",
                        field: "detailsNumber"
                    },
                    {
                        title: "工序名称",
                        field: "procedureName"
                    },
                    {
                        title: "工序编号",
                        field: "procedureId"
                    },
                    {
                        title: "描述",
                        field: "procedureDescribe"
                    },
                    {
                        title: "工时数",
                        field: "labourHourAmount",
                        formatter: function (value, row, index) {
                            return "<input data-id='amount" + index + "'  type='text' class='form-control' value='"+value+"' readonly='readonly'/>"
                        }
                    },
                    {
                        title: "工时单位",
                        field: "amountUnit",
                        formatter: function (value, row, index) {
                            return "<input data-id='amunit" + index + "'  type='text' class='form-control' value='"+value+"' readonly='readonly'/>"
                        }
                    },
                    {
                        title: "单位工时成本",
                        field: "costPrice",
                        formatter: function (value, row, index) {
                            return "<input data-id='cprice" + index + "'  type='text' class='form-control' value='"+value+"' readonly='readonly'/>"
                        }
                    },

                    {
                        title: "工时成本小计（元）",
                        field: "subtotal",
                        formatter: function (value, row, index) {
                            return "<span id='span" + index + "'>"+value+"</span>";
                        }
                    },
                    {
                        title: "物料成本小计",
                        field: "moduleSubtotal",
                    },
                    {
                        title: "设计",
                        field: "",
                        formatter: function (value, row, index) {
                            if(row.designModuleTag=="D002-0")
                            {
                                //没有设计过，那么就显示设计按钮
                                return "<input type='button' onclick='sjmod(" + row.id + ")' value='设计' class='btn btn-primary'>" ;

                            }else {
                                //设计过，那么就显示重新设计按钮
                                return "<input type='button' onclick='resjmod(" + row.id + ")' value='重新设计' class='btn btn-success'>" ;
                            }
                        }

                    }
                ]
            };
            $("#sjmodule").bootstrapTable(paramsmodule);

        }, "json")

        $("#wlmodule").bootstrapTable("refresh")
        $("#sjmodule").bootstrapTable("refresh")

        $("#module").attr("style","display:none")
        $("#module2").attr("style","display:block")
    }

    //设计
    var rows;
    function sjmod(id) {
           $.showDialogBoxByUrl("产品",
               "${pageContext.request.contextPath}/gxwl/addmodule.jsp",{},
               function (data) {
                   if (data==1){
                       var rows2=$("#admapply").bootstrapTable("getAllSelections");
                       rows=[];
                       $.each(rows2,function (index,item) {
                           var temp={"productId":item.productId,"productName":item.productName,"costPrice":item.costPrice};
                           rows.push(temp)
                       })
                   }
               },"md")
       }


    //返回
    $("#reswl").click( function () {
        $("#module").attr("style","display:block");
        $("#module2").attr("style","display:none");
    })
</script>
</body>
</html>
